﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LDTB.Service;
using System.Data.SqlClient;
using System.IO;

namespace LDTB
{
    public partial class ConfigForm : Form
    {
        public ConfigForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataService ds = new DataService();


            string DataBaseName = this.txtDBName.Text.Trim();
            string ServerName = this.txtservername.Text.Trim();
            string UserName = this.txtUser.Text.Trim();
            string PassWord = this.txtPasword.Text.Trim();

            string str = @"Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}";
            string strcnn = string.Format(str, ServerName, DataBaseName, UserName, PassWord);

            StreamWriter f = new StreamWriter("Config.txt");
            f.WriteLine(strcnn);
            f.Close();
            

            MessageBox.Show("Lưu thành công");

        }

        private void ConfigForm_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string DataBaseName = this.txtDBName.Text.Trim();
            string ServerName = this.txtservername.Text.Trim();
            string UserName = this.txtUser.Text.Trim();
            string PassWord = this.txtPasword.Text.Trim();

            string str = @"Data Source={0};Initial Catalog={1};Persist Security Info=True;User ID={2};Password={3}";
            string strcnn = string.Format(str, ServerName, DataBaseName, UserName, PassWord);

            SqlConnection cnn = new SqlConnection(strcnn);

            try
            {

                cnn.Open();
                MessageBox.Show("Kết nối thành công");

            }
            catch
            {
                MessageBox.Show("Lỗi kết nối");

            }
            finally
            {

                cnn.Close();


            }

        }
    }
}
